package com.newmedia.sounds;
import java.io.*;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

/**
 * @author christopher 
 * started 2-29-2012 last edited: 2-29-2012
 * Developed in Linux, untested on Microsoft and Macintosh.
 */
public class Sounds {
 //sounds class responsible for making and playing sounds.
	static Sequence soundplayer;
	static Sequencer soundsequencer;
	//plays the sound specified by the file path in FileName.
	public static int playSound(String fileName){
		try{
			//Gets Java ready to play from specified file....
			soundplayer = MidiSystem.getSequence(new File(fileName));
			//create a sequence for the sequence, also set's it up
			soundsequencer = MidiSystem.getSequencer();
			soundsequencer.open();
			soundsequencer.setSequence(soundplayer);
			//starts playback of midi data.
			soundsequencer.start();
			return 0; //return 0 if successful.
		} catch (Exception e) { System.out.printf("Error : %s", e); return 1;}	
	}
	//Stops the currently playing sound.
	public static int stopSound(){
		try{ 
			soundsequencer.stop();
			return 0;
		}catch(Exception e){ System.out.printf("Error: %s", e); return 1; }
	}
	
}
